package com.zhou.demo.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zhou.demo.model.DateDetail;
import com.zhou.demo.model.MyDate;
import com.zhou.demo.zhihn.R;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

/**
 * Created by 11065 on 2016/8/17.
 */
public class DateRecycleViewAdapter extends RecyclerView.Adapter<DateRecycleViewAdapter.MyViewHolder> {

    private List<MyDate> myDates = new ArrayList<>();
    private Context context;
    private LayoutInflater layoutInflater;

    public DateRecycleViewAdapter(Context context, List<MyDate> myDates) {
        this.context = context;
        this.myDates = myDates;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public DateRecycleViewAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.my_date_item, parent, false);
        MyViewHolder viewHolder = new MyViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(DateRecycleViewAdapter.MyViewHolder holder, int position) {
        holder.date.setText(myDates.get(position).getDate());
       /* List<Object> list = new ArrayList<>();
        Iterator<DateDetail> iterator = myDates.get(position).getList().iterator();
        while (iterator.hasNext()) {
            DateDetail dateDetail = iterator.next();
            list.add(dateDetail);
        }
        //    list = myDates.get(position).getList().iterator();
        DateDetailRecycleViewAdapter dateDetailRecycleViewAdapter =
                new DateDetailRecycleViewAdapter(context, list);
        holder.recyclerView.setAdapter(dateDetailRecycleViewAdapter);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
        holder.recyclerView.setLayoutManager(layoutManager);
        dateDetailRecycleViewAdapter.notifyDataSetChanged();*/
    }

    public void update(List<MyDate> list) {
        this.myDates = list;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return myDates.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        private RecyclerView recyclerView;
        private TextView date;

        public MyViewHolder(View itemView) {
            super(itemView);
            recyclerView = (RecyclerView) itemView.findViewById(R.id.recyclerView);
            date = (TextView) itemView.findViewById(R.id.date);
        }
    }
}
